package org.nothing.ordermaster.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.hibernate.annotations.DynamicUpdate;
import org.nothing.ordermaster.enums.ProductStatusEnum;
import org.nothing.ordermaster.util.EnumUtil;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;


@Entity
@Data
@DynamicUpdate
public class ProductInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    private String productId; //没有主键自增

    /** 名字 */
    private String productName;

    /** 单价 */
    private BigDecimal productPrice = BigDecimal.valueOf(0.0);

    /** 库存 */
    private Integer productStock = 0;

    /** 描述 */
    private String productDescription;

    /** 小图 */
    private String productIcon;

    /** 状态, 0-正常 1-下架 */
    private Integer productStatus = ProductStatusEnum.UP.getCode();

    /** 目录编号 */
    private Integer categoryType;

    /** 创建时间 */
    @Column(insertable = false, updatable = false)
    private Date createTime;

    /** 更新时间 */
    @Column(insertable = false, updatable = false)
    private Date updateTime;

    /** 获取产品的枚举类: 商品的各个状态都在里面 */
    @JsonIgnore
    public ProductStatusEnum getProductStatusEnum()
    {
        return EnumUtil.getByCode(productStatus, ProductStatusEnum.class);
    }
}
